const Article = require('../models/article');

exports.getAllArticles = async (req, res) => {
  try {
    const articles = await Article.find()
      .sort({ createdAt: -1 }) // 按发布时间倒序
      .select('-__v'); // 排除版本字段

    res.status(200).json({
      success: true,
      count: articles.length,
      data: articles
    });
  } catch (err) {
    res.status(500).json({
      success: false,
      error: '获取文章列表失败'
    });
  }
};